package com.bdqn.day0106.controller;

import com.bdqn.day0106.mybatis.entity.Child;
import com.bdqn.day0106.mybatis.entity.Mother;
import com.bdqn.day0106.mybatis.entity.User;
import com.bdqn.day0106.service.ChildSevice;
import com.bdqn.day0106.service.MotherService;
import com.bdqn.day0106.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author:Corday
 * @Date:2022/01/06/10:50
 */
//@Controller
 @RestController//返回json字符串
public class MyController {
    @Resource
    private UserService us;
    @Resource
    private ChildSevice cs;
    @Resource
    private MotherService ms;
    // http://localhost:8090/go ,此处可以指定请求方式：GET/POST/PUT/DELETE(查/增/修/删)
    @RequestMapping(value = "/go",method = RequestMethod.POST )
    //@ResponseBody//json字符串
    public String go(String uname, String password) {
        boolean flag = us.findByUnameAndPass(uname, password);
        return flag ? "登录成功" : "登录失败";
    }

    //获取所有的child
    @GetMapping("/play") // http://localhost:8090/play
    //@ResponseBody
    public List<Child> play(){
        return cs.getChilds();
    }
    //查询mother
    @RequestMapping("/getMother")// http://localhost:8090/getMother
    public Mother getMother(Integer mid){
       return ms.getMother(mid);
    }
    //注册用户
    @RequestMapping("/save")// http://localhost:8090/save
    public  String saveUser(User user){
        return us.saveUser(user);
    }

}
